package cn.ad.server.persistence.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import cn.ad.server.domain.SysConfig;

@Component
public interface SysConfigDao {
	
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "config_key", property = "configKey"),
			@Result(column = "config_value", property = "configValue"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "memo", property = "descr") })
	@Select("select * from sys_config")
	public List<SysConfig> findAll();
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "config_key", property = "configKey"),
			@Result(column = "config_value", property = "configValue"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	@Select("select * from sys_config where update_time >= #{value}")
	public List<SysConfig> findAfterTime(String warmUpTime);
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "config_key", property = "configKey"),
			@Result(column = "config_value", property = "configValue"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	@Select("select * from sys_config where  status = #{status}")
	public List<SysConfig> selectAll(@Param("status") int status);

	/**
	 * 根据配置KEY更新键值
	 * @param configKey
	 * @param configValue
	 * @return
	 */
	@Update("update sys_config set config_value = #{configValue} where  config_key = #{configKey}")
	public int updateValue(@Param("configKey") String configKey, @Param("configValue") String configValue) throws DataAccessException;

}
